<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://isofttime.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: $this <498944516@qq.com>
// +----------------------------------------------------------------------
namespace app\rob\model;

use think\Model;



class RobEvent extends Model
{

    protected $insert = ['status'=>1];  
   
    public function info($key, $field = true)
    {
        
        if (!$key) return false;
        $map['id'] = $key;
        return $this->field($field)->where($map)->find();
    }

     public function check($key)
    {   
        $event=$this->info($key);

        if (!$event) return '不存在该活动';
        if ($event['start_time']>time()) return '活动还没有开始，开始时间是'.date('Y-m-d H:i:s',$event['start_time']);
        if ($event['end_time']<time()) return '活动已经过期';
       
        return $event;
    }


   public function editData(){

      $data=input("post.");
      $data['aid']=session('aid');
      if ($data['id']){
         $res = $this->allowField(true)->where('id',$data['id'])->update($data);
      }else{
         $res = $this->allowField(true)->data($data)->save();
      }
      
      return $res;
    }
    
   
}